-
Notifications
You must be signed in to change notification settings - Fork 7.7k
feat(uart): Add function to invert hardware UART Tx line #11428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Simply clone existing Rx functionality for Tx. Allow granular control over both lines. Avoid overloading HardwareSerial::begin() to change the bool invert parameter to a bitmask type. Add an untested implementation for ESP32C6, ESP32H2, ESP32P4 that references the different register naming on those chips.
👋 Hello asund, we appreciate your contribution to this project! 📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more. 🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project. Click to see more instructions ...
Review and merge process you can expect ...
|
Test Results 76 files 76 suites 16m 18s ⏱️ Results for commit e6e09ce. ♻️ This comment has been updated with latest results. |
|
This PR may need a few improvements based on how IDF 5.4.1 has changed UART driver. |
No problem at all. Let me know if there's anything I can do if you want. |
|
Waiting on changes from #11499 to be merged. Possible API for inverting any signal, including CTS/RTS and LP UART signals. |
|
Sounds great! No problem closing this issue when that lands. |
Refactor UART inversion functions to use a helper for signal inversion. Update UART bus array structure to include inversion mask.
Added functions for UART signal inversion and updated existing function signatures.
Changed setRxInvert, setTxInvert to return bool. Added setCtsInvert and setRtsInvert methods.
Added functions for UART pins signal inversion.
Added logging for signal inversion in UART functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances UART signal inversion functionality by extending support beyond RX inversion to include TX, CTS, and RTS signal inversion. The implementation introduces a generic helper function to manage signal inversion state and exposes new APIs through the HardwareSerial class.
- Adds TX, CTS, and RTS signal inversion functions alongside the existing RX inversion
- Introduces an
inv_maskfield to track combined inversion states across all UART pins - Refactors signal inversion to use a centralized helper function that properly maintains inversion state
- Updates return types from
voidtoboolto indicate operation success
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| cores/esp32/esp32-hal-uart.h | Declares new signal inversion functions and helper, updates uartSetRxInvert return type to bool |
| cores/esp32/esp32-hal-uart.c | Implements generic inversion helper and individual TX/CTS/RTS inversion functions, adds inv_mask field to uart_struct_t, updates initialization arrays |
| cores/esp32/HardwareSerial.h | Declares new signal inversion methods with bool return types |
| cores/esp32/HardwareSerial.cpp | Implements wrapper methods for new signal inversion functions |
| tests/validation/uart/uart.ino | Adds test cases for TX signal inversion in both enabled and disabled UART states |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
cores/esp32/esp32-hal-uart.c:1619
- The
uart_send_breakfunction does not preserve the existing inversion mask when toggling the TX inversion. This will clear any previously set signal inversions (RX, CTS, RTS). The function should use the uart structure'sinv_maskto preserve other signal inversions. Consider using_uart_bus_array[uartNum].inv_maskto get the current mask, toggle only the TX bit, and restore the original mask after the break.
uart_set_line_inverse(uartNum, UART_SIGNAL_TXD_INV);
esp_rom_delay_us(breakTime);
uart_set_line_inverse(uartNum, UART_SIGNAL_INV_DISABLE);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description of Change
Adds a setTxInvert(), setRtsInvert() and setCtsInvert() to HardwareSerial and corresponding uartSetTxInvert to the HAL.
Using IDF Calls instead of poking registers.
Tests scenarios
I have tested my Pull Request on Arduino-esp32 core v3.2.0 with ESP32 and ESP32-S2 Board.
I added an untested implementation for the ESP32C6, ESP32H2, ESP32P4 platform in the HAL to reflect the different register name.
Tested with CI
uart.inoand using a data analizer.Related links
N/A